package com.servicesDirectory.action.organisation.department;

import java.util.List;
import java.util.ArrayList;

import com.opensymphony.xwork2.ActionSupport;
import com.servicesDirectory.bo.organisation.department.DepartmentBOImpl;
import com.servicesDirectory.common.vo.organisation.DepartmentVO;

public class DepartmentAction extends ActionSupport {

	static final String FAIL = "fail";
    protected String error ="<font color='red'> ";
	protected List<DepartmentVO> departments ;
	protected int directorateID;
	protected String filter = "";
	protected boolean checkInclude;
	
	

	//getter and setter
	public int getDirectorateID() {
		return directorateID;
	}

	public void setDirectorateID(int directorateID) {
		this.directorateID = directorateID;
	}

	public String getFilter() {
		return filter;
	}

	public void setFilter(String filter) {
		this.filter = filter;
	}

	public boolean getCheckInclude() {
		return checkInclude;
	}

	public void setCheckInclude(boolean checkInclude) {
		this.checkInclude = checkInclude;
	}


	protected String departmentName;
	protected String shortDesc;
	protected String addr1;
	protected String addr2;
	protected String addr3;
	protected String postCode;
	protected String townName;
	protected String countyName;
	protected String countryName;
	protected int contactID;
//	protected int typeOfBusinessID;
	protected String fullDesc;
	protected String phoneNumber;
	protected String fax;
	protected String email;
	protected String webAddr;
//	protected int directorateID;
//	protected boolean isActive;
	
	
	
	
	
	//getter and setter
	public String getError(){
		return error;
	}
	
	public void setError(String error){
		this.error += error;
	}
	
	public int getContactID(){
		return contactID;
	}
	public void setContactID(int contactID){
		this.contactID = contactID;
	}
	public String getShortDesc() {
		return shortDesc;
	}

	public void setShortDesc(String shortDesc) {
		this.shortDesc = shortDesc;
	}

	public String getAddr1() {
		return addr1;
	}

	public void setAddr1(String addr1) {
		this.addr1 = addr1;
	}

	public String getAddr2() {
		return addr2;
	}

	public void setAddr2(String addr2) {
		this.addr2 = addr2;
	}

	public String getAddr3() {
		return addr3;
	}

	public void setAddr3(String addr3) {
		this.addr3 = addr3;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public String getTownName() {
		return townName;
	}

	public void setTownName(String townName) {
		this.townName = townName;
	}

	public String getCountyName() {
		return countyName;
	}

	public void setCountyName(String countyName) {
		this.countyName = countyName;
	}

	public String getCountryName() {
		return countryName;
	}

	public void setCountryName(String countryName) {
		this.countryName = countryName;
	}
//
//	public int getTypeOfBusinessID() {
//		return typeOfBusinessID;
//	}
//
//	public void setTypeOfBusinessID(int typeOfBusinessID) {
//		this.typeOfBusinessID = typeOfBusinessID;
//	}
//
	public String getFullDesc() {
		return fullDesc;
	}

	public void setFullDesc(String fullDesc) {
		this.fullDesc = fullDesc;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getWebAddr() {
		return webAddr;
	}

	public void setWebAddr(String webAddr) {
		this.webAddr = webAddr;
	}
//
//	public int getDirectorateID() {
//		return directorateID;
//	}
//
//	public void setDirectorateID(int directorateID) {
//		this.directorateID = directorateID;
//	}
//
//	public boolean isActive() {
//		return isActive;
//	}
//
//	public void setActive(boolean isActive) {
//		this.isActive = isActive;
//	}

	public DepartmentVO getDepa() {
		return depa;
	}

	public void setDepa(DepartmentVO depa) {
		this.depa = depa;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	public String getDepartmentName() {
		return departmentName;
	}

	public DepartmentVO getVo() {
		return depa;
	}

	public static String getFail() {
		return FAIL;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	public List<DepartmentVO> getDepartments(){
		return departments;
	}
	public void setDepartments(List<DepartmentVO> departments){
		this.departments = departments;
	}

	
	protected DepartmentVO depa = new DepartmentVO();
	
	private static final long serialVersionUID = 1L;

	@Override
	public String execute() {
		return SUCCESS;
	}

	public String addDepartment() {
		if(validateAdd()){
			DepartmentBOImpl bo = new DepartmentBOImpl();		
			bo.addDepartment(depa);
			return SUCCESS;
		}
		else{
			setError("</font>");
			return FAIL;
		}
	}
	
	public boolean validateAdd(){
		boolean checkAdd = false;
		if(departmentName.equals("") || departmentName == null){
			checkAdd = false;
			setError("Department can't be empty !<br/>");
		}
		if(shortDesc.equals("") || shortDesc == null)
		{
			checkAdd = false;
			setError("Short description can't be empty !<br/>");
		}
		else{
			checkAdd = true;
		}
		if(checkAdd){
			depa.setDepartmentName(departmentName);
			depa.setShortDesc(shortDesc);
			depa.setAddr1(addr1);
			depa.setAddr2(addr2);
			depa.setAddr3(addr3);
			depa.setContactID(contactID);
			depa.setCountyName(countyName);
			depa.setCountryName(countryName);
			depa.setPostcode(postCode);
			depa.setPhoneNumber(phoneNumber);
			depa.setTownName(townName);
			depa.setFullDesc(fullDesc);
			depa.setEmail(email);
			depa.setFax(fax);
			depa.setWebAddr(webAddr);
			return true;
		}
		else{
			return false;
		}
		
	}
	
	
	public String listDepartment(){
		DepartmentBOImpl bo = new DepartmentBOImpl();
		this.departments = bo.listDepartment(directorateID, filter, checkInclude);
		return SUCCESS;
	}
}